$(function(){
	var detailId=queryString('updateId');
	var flowId=queryString('flowId');
	getInformationFlow(detailId);
	requestDetail(detailId)
	var file={};

	$("#dispatch-flowId option").each(function(){
		 if(($(this).val()>=flowId) &&$(this).val()!=null){
			 $(this).hide();
		 }
	 });
	//确认修改按钮
	$("#requestUpdate").click(function(){
		 var text=$("#dispatch-flowId").val();
		
		 if(text=="null"||text==""){
			 myTool.alert({		
					title:"提示",
					context:"请选择要调配到的环节",
					isMask:true,
					
				});
			
		 }else{
			 myTool.alert({		
					title:"提示",
					context:"是否确认调配信息?",
					isMask:true,
					callback:function(){
						inputCondition(text);
					}
				});
		 }
		 
		
		

	})
	
	function inputCondition(message){
		   YuXi.util.get("DispatchInfo/dispatchInfoToAny.do",{infoId:detailId,flowId:message},function(data){
			   if(data.status){
				   myTool.alert({
					   title:data.subType,
					   context:data.msg
				   });
			   }else{
				   myTool.alert({
					   title:data.subType+"["+data.errorCode+"]",
					   context:data.msg+"[错误代码:"+data.errorCode+']'
				   });
			   }
		   });
			  
	}
	
	
	function getInformationFlow(id){
		var url="getInformationFlowByInfoId.do";
		var infoId={infoId:id};
		var object={};
		YuXi.util.get(url,infoId,function(data){
			if(data.status){
				object=data.object;
				var flow;
				
				for (var i = 0; i < object.length; i++) {
					if(object[i].lastFlowId==1){
						flow="信息管理";
					}
					if(object[i].lastFlowId==3){
						flow="复核";
					}
					if(object[i].lastFlowId==2){
						flow="初审";
					}
					if(object[i].lastFlowId==4){
						flow="审核";
					}
					var time = YuXi.getTime.get(object[i].createTime);
					
					if(object[i].remark==undefined){
						object[i].remark="";
					}
					var html = "<tr ><td style='border:none;'>" + object[i].userName + "</td>+" +
					
					"<td style='border:none;'>" +time  + "</td>" +
					"<td style='border:none;'>" + object[i].operation + "</td>" +
					"<td style='border:none;'>" + object[i].remark + "</td>" +
					
					"<td style='border:none;'>" +flow  + "</td>" +
 					"</tr>";
					$("#tbody").append(html);
				}
			}
		},function(){
			
		});
	}

	
//正则取链接传来的数据
function queryString(key)
{
    var regex_str = "^.+\\?.*?\\b"+ key +"=(.*?)(?:(?=&)|$|#)"
    var regex = new RegExp(regex_str,"i");
    var url = window.location.toString();
    if(regex.test(url)) return RegExp.$1;
    return undefined;
}






//根据id向后台请求数据详情
function requestDetail(id)
{	
	var url="getUserInformationById.do";//向后台请求数据id
	var object={}
	var sourceName;
	var personId;
	var personName;
	var dataid={informationId:id};
	YuXi.util.get(url,dataid,function(data){
		object=data.object;
		sourceName=object.informationSourceNames.split(",");
		personName=object.inputPerSonNames.split(",");
		personId=object.inputPersonID.split(",");
//		//console.log("数据请求成功"+JSON.stringify(object));
		setTimeout(function(){
			$("input[name='source']").each(function(){
				for(var i=0;i<sourceName.length;i++){
					if($(this).attr("data-na")==sourceName[i]){
						$(this).attr("checked","checked");
						break;
					}
				}
				
			});
		},30);
		
		addSelect(".sele",object.safetyPortNames);
		addSelect(".pes",object.informationClassificationNames);
		addSelect(".sort",object.informationSortNames);
		for(var i=0;i<personName.length;i++){
			if(personName[i]!=""){
				
				if(i<2){
					var html="<span class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true' ></span><span class='select-data-user' data-id="+personId[i]+">"+personName[i]+"</span>&nbsp;&nbsp;<span   class='glyphicon glyphicon-remove' aria-hidden='true'></span></span>"
			        $(".label1").append(html);
				}else
				{
					html="<span style='display:none' class='parsbox'><span  class='glyphicon glyphicon-user' aria-hidden='true' ></span><span class='select-data-user' data-id="+personId[i]+">"+personName[i]+"</span>&nbsp;&nbsp;<span   class='glyphicon glyphicon-remove' aria-hidden='true'></span></span>"
			        $(".label1").append(html);
					
				}
				 if(i==2){
					html="  ...";
					$(".label1").append(html);
				 }
				html= '<li><input type="checkbox"  data-id='+personId[i]+' value='+personName[i]+' name="Check">'+personName[i]+'</li>';
				$("#addRequest").find("ul").append(html);
			}
			
		}

		$(".briefing").text(object.informationProfile);//简介
		$(".basic").text(object.standard);//标准
		$(".step").text(object.mesure);//措施
		$(".cont").text(object.informationConternt);//内容
		file=object.appendix;
		if(file==null||file=="[]"){
			
		}else{
			file=JSON.parse(file);
			var appendix=object.appendix.substring(1,object.appendix.length-1);
			appendix=appendix.split(",");
			YuXi.appendix.get(appendix);
		}
	},function(){
		//console.log("数据请求失败");

	})

}


function addSelect(className,value){
	setTimeout(function(){
		$(className+" option").each(function(){
			if($(this).html()==value){
				$(this).attr("selected","selected");
			}
		});
	},60);
	
}





/*判断输入合法性*/
function isNull(str){
	if(str==null||str==""){
		return false;
	}else{
		return true;
	}
}


function modal(msg,cont){
	myTool.alert({		
		title:msg,
		context:cont,
		isMask:true,
		callback:function(){}
	});
}





})